<?php
/**
 * Class MinInfo.php
 *
 * Class responsible for controlling the minimum number of questions/arguments 
 * of a project, as well as the maximum time in each stage
 *
 * @author Jose Oliveira <jafo@ua.pt> 2012
 */


class MinInfo{

	private $numQuest;
	private $numArg;
	private $projectID;

	/**
	 * 
	 * @param integer $numQuest
	 * @param integer $numArg
	 * @param integer $projectID
	 */
	function __construct($numQuest, $numArg, $projectID){

		if(isset($numQuest) && isset($numArg) && isset($projectID)){
			$this->numQuest=$numQuest;
			$this->numArg=$numArg;
			$this->projectID=$projectID;
		}

	}


	/**
	 * Method used to store the criteria established by a user when creating a project
	 * The information is entered in the project creation
	 * @throws Exception
	 * @return boolean
	 */
	public function saveNewSettings(){

		$conn=new ConnDBUser();
		$conn->connect();

		$result=mysql_query("insert into minInfo(numQuest, numArg, projectID) values(
		" . $this->numQuest . ", " . $this->numArg . ", " . $this->projectID . ")");

		if(!$result){
			throw new Exception("Lamentamos mas ocorreu um erro");
		}

		try{
			$conn->disconnect($result);
			return true;
		}catch (Exception $e){
			$e->getMessage();
		}

		$conn->disconnect($result);
		return false;
	}

	/**
	 * Method used to update the criteria established by a user when creating a project
	 * The information is entered in the project update
	 * @throws Exception
	 * @return bool
	 */
	public function updateSettings(){
		
		$conn=new ConnDBUser();
		$conn->connect();

		$result=mysql_query("update minInfo set numQuest=" . $this->numQuest . ",
		numArg=" . $this->numArg . " where projectID=" . $this->projectID . "");

		if(!$result){
			throw new Exception("Lamentamos mas ocorreu um erro");
		}

		try{
			$conn->disconnect($result);
			return true;
		}catch (Exception $e){
			$e->getMessage();
		}

		$conn->disconnect($result);
		return false;
	}

	/**
	 * Method that returns a project criteria info
	 * @param integer $projectID
	 * @throws Exception
	 * @return array
	 */
	public function getSettings($projectID){
		
		$conn=new ConnDBUser();
		$conn->connect();

		$result=mysql_query("select * from minInfo where projectID=$projectID");

		if(!$result){
			throw new Exception("Lamentamos mas ocorreu um erro");
		}

		try{
			$registo=mysql_fetch_array($result);
			$conn->disconnect($result);
			return $registo;
		}catch(Exception $e){
			$e->getMessage();
		}

		$conn->disconnect($result);
		return '';
	}
}

?>